package com.atguigu.gulimall.product.exception;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayListTest3 {
    public static void main(String[] args) {
        NewStudent s1 = new NewStudent();
        NewStudent s2 = new NewStudent();
        NewStudent s3 = new NewStudent();

        ArrayList<NewStudent> array = new ArrayList<>();

        array.add(s1);
        array.add(s2);
        array.add(s3);


        for(int i=0; i<array.size(); i++){
            Scanner sc = new Scanner(System.in);
            NewStudent s = array.get(i);
            System.out.print("请输入第" + (i+1) + "个学生的姓名：");
            String name = sc.nextLine();
            s.setName(name);

            System.out.print("请输入第" + (i+1) + "个学生的年龄：");
            int age = sc.nextInt();
//            sc.nextLine();
            s.setAge(age);
        }

        System.out.println("\n下面将输出各位学生的姓名和年龄等信息：");
        for(int i=0; i<array.size(); i++){
            NewStudent s = array.get(i);
            System.out.println("学生" + (i+1) + "的姓名是：" + s.getName() + "; 年龄是：" + s.getAge());
        }
    }
}

class NewStudent{
    private String name;
    private int age;

    public NewStudent(){}

    public NewStudent(String name, int age){
        this.name = name;
        this.age = age;
    }

    public void setName(String name){
        this.name = name;
    }
    public String getName(){
        return name;
    }

    public void setAge(int age){
        this.age = age;
    }
    public int getAge(){
        return age;
    }
}